#!/usr/bin/env bash

# check docker image for building
if [ "$(docker images -q appnet-bld:4.1 2> /dev/null)" == "" ]; then
  echo "Build Docker image as appnet-bld:4.1"
  docker image build --rm --network host --compress -t appnet-bld:4.1 -f ./Dockerfile.bld .
fi

# execute commands 
if [ $# -ne 0 ]; then
  echo "$@ ..."
  docker run -v `pwd`:`pwd` -w `pwd` -i -t --rm --network host appnet-bld:4.1 $@
else
  echo "Start building ..."
  docker run -v `pwd`:`pwd` -w `pwd` -i -t --rm --network host appnet-bld:4.1 \
  bash -c "npm config set registry=http://registry.npm.taobao.org && \
           npm i --only=prod && ./tools/genSrvKey.bash 51dese.com"
fi
